package com.linwen.javase.juc;

import java.util.concurrent.CountDownLatch;

/**
 * @ClassName _12CountDownLunchThread
 * @Description
 * @Author lin
 * @Date 2022/4/21 下午11:51
 * @Version V1.0
 *
 *countDownLatch 减少计数  给定初始值，当初始值减为0,当前阻塞的线程才会继续往下执行
 */
public class _12CountDownLunchThread {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        // 当线程都执行完再继续执行主线程
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+" 执行完毕");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"  over");
    }
}
